<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('直播课列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('node:edit')}]];
    var removeFlag = [[${@permission.hasPermi('node:remove')}]];
    var nodeTypeDatas = [[${@dict.getType('qdx_node_type')}]];
    var fileTypeDatas = [[${@dict.getType('qdx_node_file_type')}]];
    var prefix = "/course/node";

    $(function() {
        var options = {
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            url: prefix + "/live/list.json",
            createUrl: prefix + "/add.html",
            updateUrl: prefix + "/edit.html?id={id}",
            removeUrl: prefix + "/remove.json",
            modalName: "知识点的基本信息",
            columns: [
                {
                    field: 'nodeId',
                    title: 'id',
                },
                {
                    field: 'name',
                    title: '直播房间名称'
                },
                {   field:'nodeKey',
                    title: '房间号'
                },
                {
                    field: 'liveBeginTime',
                    title: '直播开始时间'
                },
                {
                    field: 'liveEndTime',
                    title: '直播结束时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                       var actions = [];
                       var endTime = StrToData(row.liveEndTime);
                       var timestamp = Date.parse(new Date());
                       if(timestamp < endTime){
                           actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick=toLiveRoom("'+row.nodeKey+'","1","WEB")><i class="fa fa-video-camera"></i> 进入直播间</a>');
                       }else{
                           actions.push('<a class="btn btn-default btn-xs" disabled="disabled" href="javascript:void(0)"><i class="fa fa-ban"></i> 直播已结束</a> ');
                       }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*老师进入直播间*/
    function toLiveRoom(roomId,role,type) {
        $.ajax({
            url:"/course/node/live/into.json",
            data:{"id":roomId,"role":role,"type":type},
            type: "post",
            dataType:"json",
            success:function(json){
                if(type==="WEB"){
                    window.open(json.msg);
                }else {
                    window.location.href = json.msg;
                }
            }
        });
    }

    //将字符串转时间戳
    function StrToData(date) {
        return new Date(date).getTime();
    }
</script>
</body>
</html>
